export default class CircularBuffer {
  size: any
  index: number
  buffer: any[]
  sorted: boolean
  constructor(e) {
    this.size = e
    this.index = 0
    this.buffer = []
    this.sorted = !1
  }
  push(e) {
    this.index >= this.size && (this.index = 0)
    this.buffer[this.index] = e
    this.index++
    this.sorted = !1
  }
  peek() {
    return this.buffer[this.index <= this.buffer.length ? this.index - 1 : 0] || null
  }
  getList() {
    return this.buffer
  }
  median() {
    const e = Math.floor(this.buffer.length / 2)
    this.sorted || this.buffer.sort()
    return this.buffer[e]
  }
  *[Symbol.iterator]() {
    yield* this.buffer
  }
  clear() {
    this.buffer = []
    this.index = 0
  }
}
